import StorageUtils from "../../../../app/storage";
import Utils from "../../../../utils/index";
import DB from '../../../../app/db';

export const RwCode = {
  CAST01: 'CAST01',
  CAST02: 'CAST02',
  CAST03: 'CAST03',
  CAST04: 'CAST04'
};

export const RwCodeArray = ['CAST01', 'CAST02', 'CAST03', 'CAST04'];

// 学历
export const RECORD = [{value: '1', label: '小学'}, {value: '2', label: '初中'}, {value: '3', label: '技工学校'}, {value: '4', label: '职业高中'}, {value: '5', label: '普通高中'}, {value: '6', label: '中专'}, {value: '7', label: '大专'}, {value: '8', label: '本科'}, {value: '9', label: '硕士'}, {value: '10', label: '博士'}, {value: '11', label: '其它'}];

export function getProprietorByOpenId(openId) {
  DB.WechatAPI.getProprietorByOpenId({openId: openId}).then(
    function (content) {
      if (content && content.id) {
        StorageUtils.updateUser({proprietorId: content.id});
        StorageUtils.setStorage('proprietor', content);
      } else {
        StorageUtils.updateUser({proprietorId: ''});
        StorageUtils.removeStorageItem('proprietor');
      }
    },
    function (error) {
      StorageUtils.updateUser({proprietorId: ''});
      StorageUtils.removeStorageItem('proprietor');
      Utils.myAlert(error);
    }
  ).catch(function (reason) {
    Utils.myAlert(reason);
  });
}

export function getInfoByOpenId(openId) {
  DB.WechatAPI.getInfoByOpenId({
    openId: openId,
  }).then(
    function (content) {
      if (content.length > 0) {
        StorageUtils.setStorage('doors', content);
      } else {
        StorageUtils.removeStorageItem('doors');
      }
    },
    function (error) {
      StorageUtils.removeStorageItem('doors');
      Utils.myAlert(error);
    }
  ).catch(function (reason) {
    Utils.myAlert(reason);
  });
}
